package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("/admin/comment")
@CrossOrigin
public class CommentController {

    @Autowired
    private DtsCommentService dtsCommentService;
    @RequiresPermissionsDesc(menu = {"商场管理","商品评论"},button ="查找")
    @RequiresPermissions("admin:comment:list")
    @GetMapping("/list")
    public Object commentList(@RequestParam(defaultValue = "1")Integer page,
                              @RequestParam(defaultValue = "20") Integer limit,
                              @RequestParam(defaultValue = "add_time") String sort,
                              @RequestParam(defaultValue = "desc") String order){

        IPage<DtsComment> iPage = dtsCommentService.findPage(page,limit,sort,order);
        List<DtsComment> records = iPage.getRecords();
        long total = iPage.getTotal();
        Map map = new HashMap();
        map.put("total",total);
        map.put("items", records);
        return ResponseUtil.ok(map);
    }
    @RequiresPermissionsDesc(menu = {"商场管理","商品评论"},button ="删除")
    @RequiresPermissions("admin:comment:delete")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsComment dtsComment){

        dtsCommentService.delete(dtsComment);

        return ResponseUtil.ok();
    }



}
